package ru.reinvent.perspectiva.cash;

import java.util.ArrayList;

import ru.reinvent.perspectiva.R;

import android.content.Context;
import android.content.res.Resources;

public class ContactsModel 
	{
	private Contact moscow;
	private Contact peter;
	private Contact almati;
	private Contact eburg;
	private Contact kyev;
	
	public ContactsModel(Context ctx) 
		{
		Resources r = ctx.getResources();
		
		moscow = new Contact();
		moscow.setTown(r.getString(R.string.contacts_moscow_title));
		moscow.setAddress(r.getString(R.string.contacts_moscow_address));
		moscow.setHours(r.getString(R.string.contacts_moscow_hours));
		moscow.setPhones(createPhonesList(r.getStringArray(R.array.contacts_moscow_phones)));

		peter = new Contact();
		peter.setTown(r.getString(R.string.contacts_peter_title));
		peter.setAddress(r.getString(R.string.contacts_peter_address));
		peter.setHours(r.getString(R.string.contacts_peter_hours));
		peter.setPhones(createPhonesList(r.getStringArray(R.array.contacts_peter_phones)));

		almati = new Contact();
		almati.setTown(r.getString(R.string.contacts_almati_title));
		almati.setAddress(r.getString(R.string.contacts_almati_address));
		almati.setHours(r.getString(R.string.contacts_almati_hours));
		almati.setPhones(createPhonesList(r.getStringArray(R.array.contacts_almati_phones)));

		eburg = new Contact();
		eburg.setTown(r.getString(R.string.contacts_eburg_title));
		eburg.setAddress(r.getString(R.string.contacts_eburg_address));
		eburg.setHours(r.getString(R.string.contacts_eburg_hours));
		eburg.setPhones(createPhonesList(r.getStringArray(R.array.contacts_eburg_phones)));

		kyev = new Contact();
		kyev.setTown(r.getString(R.string.contacts_kyev_title));
		kyev.setAddress(r.getString(R.string.contacts_kyev_address));
		kyev.setHours(r.getString(R.string.contacts_kyev_hours));
		kyev.setPhones(createPhonesList(r.getStringArray(R.array.contacts_kyev_phones)));
		}
	
	protected ArrayList<String> createPhonesList(String[] arr)
		{
		ArrayList<String> phones = new ArrayList<String>();
		for (String phone : arr) phones.add(phone);
		return phones;
		}
	
	public Contact getMoscowContact() { return moscow; }
	public Contact getPeterContact() { return peter; }
	public Contact getAlmatiContact() { return almati; }
	public Contact getEkaterinburgContact() { return eburg; }
	public Contact getKyevContact() { return kyev; }
	
	public class Contact
		{
		private String town;
		private String address;
		private String hours;
		private ArrayList<String> phones;
		
		public void setTown(String val) { town = val; }
		public void setAddress(String val) { address = val; }
		public void setHours(String val) { hours = val; }
		public void setPhones(ArrayList<String> val) { phones = val; }
		
		public void addPhone(String val) 
			{ 
			if (phones == null) phones = new ArrayList<String>();
			phones.add(val); 
			}
		
		public String getTown() { return town; }
		public String getAddress() { return address; }
		public String getHours() { return hours; }
		
		public String getPhone(int ind) 
			{ 
			if (phones == null) 
				{
				phones = new ArrayList<String>();
				return null;
				}
			return phones.get(ind); 
			}
		
		public ArrayList<String> getPhones() 
			{ 
			if (phones == null) phones = new ArrayList<String>();
			return phones; 
			}
		}

}
